package com.ztsoft.user.controller.project;

import com.ztsoft.user.pojo.entity.project.Project;
import com.ztsoft.user.service.project.ProjectService;
import com.ztsoft.user.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Slf4j
@CrossOrigin("*")
@RestController
@RequestMapping("/project")
@Api(tags = "项目控制层")
public class ProjectController {

    @Resource
    private ProjectService projectService;

    @GetMapping("/getProject/{pageSize}/{currentPage}")
    @ApiOperation(value = "根据关联关系查找用户可查项目", notes = "根据关联关系查找用户可查项目")
    public Result<Object> getProject(@PathVariable("currentPage") Integer currentPage,
                                     @PathVariable("pageSize") Integer pageSize,
                                     @RequestParam(value = "infoNumber", required = false) String infoNumber,
                                     @RequestParam(value = "projectName", required = false) String projectName) {
        return projectService.getProject(currentPage, pageSize, infoNumber, projectName);
    }

    @GetMapping("/getUserAndProject/{projectId}/{pageSize}/{currentPage}")
    @ApiOperation(value = "根据关联关系查询项目可分配用户", notes = "根据关联关系查询项目可分配用户")
    public Result<Object> getUserAndProject(@PathVariable("projectId") String projectId,
                                            @PathVariable("currentPage") Integer currentPage,
                                            @PathVariable("pageSize") Integer pageSize,
                                            @RequestParam(value = "userAccount", required = false) String userAccount,
                                            @RequestParam(value = "userName", required = false) String userName,
                                            @RequestParam(value = "roleName", required = false) String roleName,
                                            @RequestParam(value = "region", required = false) String region) {
        return projectService.getUserAndProject(projectId, currentPage, pageSize, userAccount, userName, roleName, region);
    }

    @GetMapping("/getExistUserAndProject/{projectId}/{pageSize}/{currentPage}")
    @ApiOperation(value = "根据关联关系查询项目已存在关系用户", notes = "根据关联关系查询项目已存在关系用户")
    public Result<Object> getExistUserAndProject(@PathVariable("projectId") String projectId,
                                                 @PathVariable("currentPage") Integer currentPage,
                                                 @PathVariable("pageSize") Integer pageSize) {
        return projectService.getExistUserAndProject(projectId, currentPage, pageSize);
    }

    @PutMapping("/updateUserAndProject/{projectId}/{type}")
    @ApiOperation(value = "修改用户与项目关系", notes = "修改用户与项目关系")
    public Result<Object> updateUserAndProject(@PathVariable("projectId") String projectId,
                                               @PathVariable("type") Integer type,
                                               @RequestBody List<String> userIds) {
        return projectService.updateUserAndProject(projectId, type, userIds);
    }

    @GetMapping("/getChildAgencies/{pageSize}/{currentPage}")
    @ApiOperation(value = "查找子代理机构账号", notes = "查找子代理机构账号")
    public Result<Object> getChildAgencies(@PathVariable("currentPage") Integer currentPage,
                                           @PathVariable("pageSize") Integer pageSize,
                                           @RequestParam(value = "userAccount", required = false) String userAccount,
                                           @RequestParam(value = "userName", required = false) String userName,
                                           @RequestParam(value = "region", required = false) String region) {
        return projectService.getChildAgencies(currentPage, pageSize, userAccount, userName, region);
    }

    @GetMapping("/getUserAndManage/{manageId}/{pageSize}/{currentPage}")
    @ApiOperation(value = "根据关联关系查询管理可分配用户", notes = "根据关联关系查询管理可分配用户")
    public Result<Object> getUserAndManage(@PathVariable("manageId") String manageId,
                                           @PathVariable("currentPage") Integer currentPage,
                                           @PathVariable("pageSize") Integer pageSize,
                                           @RequestParam(value = "userAccount", required = false) String userAccount,
                                           @RequestParam(value = "userName", required = false) String userName,
                                           @RequestParam(value = "roleName", required = false) String roleName,
                                           @RequestParam(value = "region", required = false) String region) {
        return projectService.getUserAndManage(manageId, currentPage, pageSize, userAccount, userName, roleName, region);
    }

    @GetMapping("/getExistUserAndManage/{manageId}/{pageSize}/{currentPage}")
    @ApiOperation(value = "根据关联关系查询管理已存在关系用户", notes = "根据关联关系查询管理已存在关系用户")
    public Result<Object> getExistUserAndManage(@PathVariable("manageId") String manageId,
                                                @PathVariable("currentPage") Integer currentPage,
                                                @PathVariable("pageSize") Integer pageSize,
                                                @RequestParam(value = "userName", required = false) String userName,
                                                @RequestParam(value = "region", required = false) String region) {
        return projectService.getExistUserAndManage(manageId, currentPage, pageSize, userName, region);
    }

    @PutMapping("/updateUserAndManage/{manageId}/{type}")
    @ApiOperation(value = "修改管理者与用户关系", notes = "修改管理者与用户关系")
    public Result<Object> updateUserAndManage(@PathVariable("manageId") String manageId,
                                              @PathVariable("type") Integer type,
                                              @RequestBody List<String> userIds) {
        return projectService.updateUserAndManage(manageId, type, userIds);
    }

    @GetMapping("/queryUserAndDemandUnit/{pageSize}/{currentPage}")
    @ApiOperation(value = "查询分配用户", notes = "查询分配用户")
    public Result<Object> queryUserAndDemandUnit(@PathVariable("currentPage") Integer currentPage,
                                                 @PathVariable("pageSize") Integer pageSize,
                                                 @RequestParam(value = "userName", required = false) String userName,
                                                 @RequestParam(value = "demandUnitName", required = false) String demandUnitName,
                                                 @RequestParam(value = "region", required = false) String region,
                                                 @RequestParam(value = "userCreateTime", required = false) Date userCreateTime,
                                                 @RequestParam(value = "demandUnitCreateTime", required = false) Date demandUnitCreateTime) {
        return projectService.queryUserAndDemandUnit(currentPage, pageSize, userName, demandUnitName, region, userCreateTime, demandUnitCreateTime);
    }

    @PutMapping("/updateUserAndQuote/{userId}/{type}")
    @ApiOperation(value = "管理用户与物资关系", notes = "管理用户与物资关系")
    public Result<Object> updateUserAndQuote(@PathVariable("userId") String userId,
                                             @PathVariable("type") Integer type,
                                             @RequestBody List<String> quoteIds) {
        return projectService.updateUserAndQuote(userId, type, quoteIds);
    }

    @PutMapping("/updateProject")
    @ApiOperation(value = "修改项目", notes = "修改项目")
    public Result<Object> updateProject(@RequestBody Project project) {
        return projectService.updateProject(project);
    }

    @PostMapping("/addProject")
    @ApiOperation(value = "添加项目", notes = "添加项目")
    public Result<Object> addProject(@RequestBody Project project) {
        return projectService.addProject(project);
    }

    @DeleteMapping("/deleteProject/{id}")
    @ApiOperation(value = "删除项目", notes = "删除项目")
    public Result<Object> deleteProject(@PathVariable("id") String id) {
        return projectService.deleteProject(id);
    }

}